package spring.superrun.record.mvc.Aop;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import spring.superrun.record.mvc.dto.ManagerCookieDto;
import spring.superrun.record.mvc.service.SuperrunManagerService;
import spring.superrun.record.mvc.setup.CookieConfig;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

//
//public class AuthenticationInterceptor implements HandlerInterceptor {
////    @Autowired
////    private SuperrunManagerService _managerService;
////    /**
////     * 在请求处理前调用(Controller 方法)
////     * @param request
////     * @param response
////     * @param handler
////     * @return
////     * @throws Exception
////     */
////    @Override
////    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
////        try {
////            //统一拦截（查询当前session是否存在user）(这里user会在每次登陆成功后，写入session)
////            Object obj=request.getSession().getAttribute(CookieConfig.SYSTEM_USER_SESSION);
////            if(obj!=null){
////                return true;
////            }
////            response.sendRedirect(request.getContextPath()+"/auth/login");
////            // 已经登录
////            return true;
////        } catch (IOException e) {
////            e.printStackTrace();
////        }
////        return false;//如果设置为false时，被请求时，拦截器执行到此处将不会继续操作
////        //如果设置为true时，请求将会继续执行后面的操作
////    }
////    /**
////     * 在整个请求结束之后被调用，也就是在DispatcherServlet 渲染了对应的视图之后执行（主要是用于进行资源清理工作）
////     */
////    @Override
////    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
////    //        System.out.println("执行了TestInterceptor的afterCompletion方法");
////    }
//}
